/**
 * Copyright (C) 2009+ Spark Zheng
 *
 * @file        src/reactor.h 
 * @date        2010-04-05
 * @brief	server_framework
 * @see         dserver
 * @history
 */

#ifndef _DSERVER_REACTOR_H
#define _DSERVER_REACTOR_H

#ifdef __cplusplus
extern "C" {
#endif

#include <unistd.h>
#include <event.h>

#include <dlib/global.h>
#include <dlib/lock.h>
#include <dlib/list.h>
#include <dlib/threadpool.h>

#include "dserver.h"
#include "dserver_log.h"
#include "dserver_errno.h"
#include "prot_types.h"

/** reactor pipe_fd buffer size */
#ifndef REACTOR_PIPE_BUF_SIZE
#define REACTOR_PIPE_BUF_SIZE	16U
#endif

struct reactor_context {
	struct event		r_pipe_event;	/** done notify event */
	int			r_done_pipe[2];	/** done notify pipe */

	struct event_base	*r_main_event;	/** reactor main event */
	dserver_cpool_t		*r_cpool;	/** tcp connection pool */
};

/**
 * reactor_init
 * @brief construct reactor module
 * @param dc: main context struct
 */
extern int reactor_init(dserver_t *dc);

/**
 * reactor_run
 * @brief running all protocols forever
 * @param dc: main context struct
 */
extern int reactor_run(dserver_t *dc);

/**
 * reactor_exit
 * @brief destruct reactor module
 * @param dc: main context struct
 */
extern void reactor_exit(dserver_t *dc);

#ifdef __cplusplus
}
#endif
#endif
